package com.kclm.se.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.List;

public class ServerThread extends Thread {

	private Socket socket;
	
	private List<Socket> allSocket;

	/**
	 * @return the socket
	 */
	public Socket getSocket() {
		return socket;
	}

	/**
	 * @param socket the socket to set
	 */
	public void setSocket(Socket socket) {
		this.socket = socket;
	}

	/**
	 * @return the allSocket
	 */
	public List<Socket> getAllSocket() {
		return allSocket;
	}

	/**
	 * @param allSocket the allSocket to set
	 */
	public void setAllSocket(List<Socket> allSocket) {
		this.allSocket = allSocket;
	}

	/**
	 * @param socket
	 * @param allSocket
	 */
	public ServerThread(Socket socket, List<Socket> allSocket) {
		this.socket = socket;
		this.allSocket = allSocket;
	}

	@Override
	public void run() {
		//todo 
		try(BufferedReader br = 
				new BufferedReader(
						new InputStreamReader(socket.getInputStream()));
				PrintWriter out = new PrintWriter(socket.getOutputStream(),true)) {
			//从客户端读取数据
			String line = br.readLine();
			System.out.println("客户说："+line);
			//往客户端写：
			out.println("服务端说：你好！");
			//
		
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	
}
